package com.ymatou.iapi.godmch.testcase;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.condition;
import com.ymatou.iapi.godmch.parameter.setConditionLevelBean;
import com.ymatou.iapi.godmch.parameter.setConditionMarkupConfigBean;
import com.ymatou.iapi.godmch.service.setConditionLevelCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmch.markup_condition_level;
import com.ymttest.database.model.godmch.markup_condition_levelExample;
import com.ymttest.database.sqlwapper.godmch.markup_condition_levelWapper;
/**
*设置加价条件类型优先级
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_setConditionLevel{
	private static setConditionLevelBean bean;
	private static setConditionLevelCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置加价条件类型优先级");
	}

	@Before
	public void caseUp() {
		bean=new setConditionLevelBean();
		call=new setConditionLevelCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setConditionLevel_001() {
		Logger.start(true,"设置加价条件类型优先级-设置一条类型-返回成功");
		try {
			
		    Integer agentId=GodmchManageCallService.createAgent();
            Integer supplierId=GodmchManageCallService.createApplySupplier().getSupplierId();
			//新增
            setConditionMarkupConfigBean setBean=GodmchManageCallService.initSetConditionMarkupConfig(agentId,supplierId);
            GodmchManageCallService.setConditionMarkupConfigCall(setBean);
            
            bean.setAgentId(agentId);
            bean.setSupplierId(supplierId);
            
		    List<condition> lst=new ArrayList<condition>();
   		    condition con=new condition();
   		    con.setConditionType(5);
   		    con.setConditionLevel(2);
   		    lst.add(con);
	   		bean.setList(lst);
			call.setData(bean);
			call.callService();			
			
		   markup_condition_levelWapper markupConfig=new markup_condition_levelWapper();
		   markup_condition_levelExample example=new markup_condition_levelExample();
		   example.createCriteria().andAgent_idEqualTo(agentId).andSupplier_idEqualTo(supplierId);
		   markup_condition_level level=markupConfig.selectByExample(example).get(0);
			
		  Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
		  Logger.verifyEquals(bean.getAgentId(), level.getAgent_id(), "验证数据库markup_condition_level表中的Agent_id字段与传入的一致");
		  Logger.verifyEquals(bean.getSupplierId(), level.getSupplier_id(), "验证数据库markup_condition_level表中的Supplier_id字段与传入的一致");
		  Logger.verifyEquals(bean.getList().get(0).getConditionType(), level.getType_id(), "验证数据库markup_condition_level表中的Type_id字段与传入的一致");
		  
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setConditionLevel_002() {
		Logger.start(true,"设置加价条件类型优先级-设置两条类型-返回成功");
		try {

		    Integer agentId=GodmchManageCallService.createAgent();
            Integer supplierId=GodmchManageCallService.createApplySupplier().getSupplierId();
			//新增
            setConditionMarkupConfigBean setBean=GodmchManageCallService.initSetConditionMarkupConfig(agentId,supplierId);
            GodmchManageCallService.setConditionMarkupConfigCall(setBean);
            
            bean.setAgentId(agentId);
            bean.setSupplierId(supplierId);
            
		    List<condition> lst=new ArrayList<condition>();
		    //添加一条
   		    condition con=new condition();
   		    con.setConditionType(5);
   		    con.setConditionLevel(2);
   		    lst.add(con);
   		    //添加两条
   		    con=new condition();
   		    con.setConditionType(3);
   		    con.setConditionLevel(1);
   		    lst.add(con);
	   		bean.setList(lst);
			call.setData(bean);
			call.callService();			
			
			
		   markup_condition_levelWapper markupConfig=new markup_condition_levelWapper();
		   markup_condition_levelExample example=new markup_condition_levelExample();
		   example.createCriteria().andAgent_idEqualTo(agentId).andSupplier_idEqualTo(supplierId);
		   List<markup_condition_level> levels=markupConfig.selectByExample(example);
			
		  Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
		  Logger.verifyEquals(bean.getAgentId(), levels.get(0).getAgent_id(), "验证数据库markup_condition_level表中的Agent_id字段与传入的一致");
		  Logger.verifyEquals(bean.getSupplierId(), levels.get(0).getSupplier_id(), "验证数据库markup_condition_level表中的Supplier_id字段与传入的一致");
		  Logger.verifyEquals(bean.getList().get(1).getConditionType(), levels.get(0).getType_id(), "验证数据库markup_condition_level表中的Type_id字段与传入的一致");			
		  Logger.verifyEquals(bean.getList().get(0).getConditionType(), levels.get(1).getType_id(), "验证数据库markup_condition_level表中的Type_id字段与传入的一致");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setConditionLevel_002_1() {
		Logger.start(true,"设置加价条件类型优先级-1分钟内不可以再执行-返回失败");
		try {

		    Integer agentId=GodmchManageCallService.createAgent();
            Integer supplierId=GodmchManageCallService.createApplySupplier().getSupplierId();
			//新增
            setConditionMarkupConfigBean setBean=GodmchManageCallService.initSetConditionMarkupConfig(agentId,supplierId);
            GodmchManageCallService.setConditionMarkupConfigCall(setBean);
            
            bean.setAgentId(agentId);
            bean.setSupplierId(supplierId);
            
		    List<condition> lst=new ArrayList<condition>();
		    //添加一条
   		    condition con=new condition();
   		    con.setConditionType(5);
   		    con.setConditionLevel(2);
   		    lst.add(con);
	   		bean.setList(lst);
			call.setData(bean);
			call.callService();	
			 //重新执行
   		    con=new condition();
   		    con.setConditionType(3);
   		    con.setConditionLevel(1);
   		    lst.add(con);
	   		bean.setList(lst);
	   		call.setData(bean);
			call.callService();			
			Logger.verifyEquals("5000", call.getStatusCode1(), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setConditionLevel_003() {
		Logger.start(true,"设置加价条件类型优先级-代理商id为空-返回失败");
		try {
		    Integer agentId=GodmchManageCallService.createAgent();
            Integer supplierId=GodmchManageCallService.createApplySupplier().getSupplierId();
			//新增
            setConditionMarkupConfigBean setBean=GodmchManageCallService.initSetConditionMarkupConfig(agentId,supplierId);
            GodmchManageCallService.setConditionMarkupConfigCall(setBean);
            
           // bean.setAgentId(agentId);
            bean.setSupplierId(supplierId);
            
		    List<condition> lst=new ArrayList<condition>();
   		    condition con=new condition();
   		    con.setConditionType(5);
   		    con.setConditionLevel(2);
   		    lst.add(con);
	   		bean.setList(lst);
			call.setData(bean);
			call.callService();				
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setConditionLevel_004() {
		Logger.start(true,"设置加价条件类型优先级-供货商id为空-返回失败");
		try {
		    Integer agentId=GodmchManageCallService.createAgent();
            Integer supplierId=GodmchManageCallService.createApplySupplier().getSupplierId();
			//新增
            setConditionMarkupConfigBean setBean=GodmchManageCallService.initSetConditionMarkupConfig(agentId,supplierId);
            GodmchManageCallService.setConditionMarkupConfigCall(setBean);
            
            bean.setAgentId(agentId);
          //  bean.setSupplierId(supplierId);
            
		    List<condition> lst=new ArrayList<condition>();
   		    condition con=new condition();
   		    con.setConditionType(5);
   		    con.setConditionLevel(2);
   		    lst.add(con);
	   		bean.setList(lst);
			call.setData(bean);
			call.callService();				
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setConditionLevel_005() {
		Logger.start(true,"设置加价条件类型优先级-list为空-返回失败");
		try {
		    Integer agentId=GodmchManageCallService.createAgent();
            Integer supplierId=GodmchManageCallService.createApplySupplier().getSupplierId();
			//新增
            setConditionMarkupConfigBean setBean=GodmchManageCallService.initSetConditionMarkupConfig(agentId,supplierId);
            GodmchManageCallService.setConditionMarkupConfigCall(setBean);
            
            bean.setAgentId(agentId);
            bean.setSupplierId(supplierId);
            
//		    List<condition> lst=new ArrayList<condition>();
//   		    condition con=new condition();
//   		    con.setConditionType(5);
//   		    con.setConditionLevel(2);
//   		    lst.add(con);
//	   		bean.setList(lst);
			call.setData(bean);
			call.callService();				
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}